package com.origin.onlinesys.service.modules.user.impl;

import com.origin.onlinesys.common.services.BaseService;
import com.origin.onlinesys.domain.modules.interviewsys.Permission;
import com.origin.onlinesys.persistence.modules.sys.account.PermissionMapper;
import com.origin.onlinesys.service.modules.user.IPermissionsService;
import org.springframework.stereotype.Service;

import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2015/3/6.
 */
@Service
public class PermissionServiceImplShiro extends BaseService<Permission> implements IPermissionsService {

    @Override
    public Map<String, String> selectAllAsMap() {
        Map<String,String> permissionUrl = new HashMap<String,String>();
        List<Permission> list = ((PermissionMapper)mapper).selectAllPermission();
        StringBuilder sb;
        for(Permission bean:list){
            sb = new StringBuilder("authc,perms[");
            sb.append(bean.getPerName());sb.append("]");
            permissionUrl.put(bean.getPerUrl(),sb.toString());
        }
        return permissionUrl;
    }

    @Override
    public Collection<org.apache.shiro.authz.Permission> selectAllAsObjPermissions() {
        return null;
    }

    @Override
    public Collection<org.apache.shiro.authz.Permission> selectByUserIdAsObjPermissions(String id) {
        return null;
    }

    @Override
    public Collection<String> selectByUserIdAsStrPermissions(String id) {
        return  ((PermissionMapper)mapper).selectByUserId(id);
    }

    @Override
    public int addMenuPermission(List<Map> list){
        ((PermissionMapper)mapper).addMenuPermission(list);
        return 1;
    }

    @Override
    public List<Permission> selectItem() {
        return ((PermissionMapper)mapper).selectItem();
    }

    @Override
    public Permission selectById(String id) {
        return ((PermissionMapper)mapper).selectById(id);
    }

    @Override
    public List<String> selectMIdByPId(String id) {
        return ((PermissionMapper)mapper).selectMIdByPId(id);
    }

    @Override
    public int delMenuPermission(String id) {
        ((PermissionMapper)mapper).delMenuPermission(id);
        return 1;
    }
}
